package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Product;
import com.nbsaas.boot.product.api.domain.request.ProductRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.shop.data.entity.Shop;
            import com.nbsaas.boot.product.data.entity.ProductGroup;

/**
* 商品请求对象转换成实体对象
*/

public class ProductEntityConvert  implements Converter<Product, ProductRequest> {

    @Override
    public Product convert(ProductRequest source) {
        Product result = new Product();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getShop()!=null){
                    Shop shop =new Shop();
                    shop.setId(source.getShop());
                    result.setShop(shop);
                    }
                    if(source.getProductGroup()!=null){
                    ProductGroup productGroup =new ProductGroup();
                    productGroup.setId(source.getProductGroup());
                    result.setProductGroup(productGroup);
                    }
        return result;
    }
}

